package javamysql;

import static org.junit.Assert.*;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

import org.junit.Test;

public class PreparedStatementTest {

	@Test
	public void test() {
		String URL = "jdbc:mysql://localhost:3306/test";
		String driverName = "com.mysql.jdbc.Driver";
		String userName = "root";//root
		String password = "wujiantong";//123456
		PreparedStatement pStatement = null;
		Connection conn = null;
		try {
			conn = DriverManager.getConnection(URL, userName, password);
			for (int i = 0; i < 1000; i++) {
				String strSql = "insert into students(stuno,name) values(?,?)";
				pStatement = conn.prepareStatement(strSql);
				pStatement.setString(1, "201521123056");
				pStatement.setString(2, "wujiantong");
				pStatement.executeUpdate();//添加到同一个批处理中
			}
		} catch (SQLException e) {
			// TODO: handle exception
		}finally{
			if(conn!=null)
				try {
					conn.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			conn = null;
		}
	}

}
